
import React from "react";
import createYGCPage from '../../components/CreateYGCPage/index.jsx'
import App from 'layout/App.js';
import "./index.less";

import Table from "bee-table";
import 'bee-table/build/Table.css';

import { searchTpl } from './tpl/searchTpl.js'
import { setTableTpl } from './tpl/tableTpl.js'
import { queryProject } from './projectIndicators.config.js'

import { vendorsSetUrl, vendorsTrimStr, vendorsDanger, vendorsFmtDate, vendorsSuccess, vendorsGetUrlParam } from 'utils/config.js';


class ProjectIndicators extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: []
        };
        this.srcHeight = 60;
        this.columns = setTableTpl(this);
        this.searchTpl = searchTpl;
    }
    componentDidMount() {

    }

    render() {
        let { searchTpl } = this.state;
        return (
            <App>
                <div className="ygc-list">
                    <div className='ygc-list-header-area'>
                        <div className='ygc-list-header-title'>项目指标统计表</div>
                    </div>
                    <div className="ygc-search-Area">
                        {this.props.YGCCreateSearch(this.searchTpl, { searchBtnClick: this.searchBtnClick })}
                    </div>
                    <div className="ygc-table-Area">
                        <div className="ygc-projectIndicators-table">
                            <Table
                                className='project_table'
                                columns={this.columns}
                                data={this.state.data}
                                showRowNum={true}
                                emptyText={() => '暂无数据'}
                                rowKey={this.setRowKey}
                                // scroll={{ y: 460 }}
                                bordered
                            />
                        </div>
                    </div>
                </div>
            </App>
        )
    }

    setScheduleCol = (key, record) => {
        if (key == 'sumNum' || key == 'name') {
            return record.scheduleShowVOS && record.scheduleShowVOS.map((item, index) => {
                let sumNumHeight = item.scheduleItemShowVOS.length;
                if (!sumNumHeight) {
                    sumNumHeight = 1
                }
                return (
                    <div style={{ height: `${this.srcHeight * sumNumHeight}px` }}
                        className={record.scheduleShowVOS.length - 1 !== index ? 'scheduleVosItem itemP' : 'itemP'}
                    >
                        {item[key]}
                    </div >
                )
            })
        }
    }

    setScheduleItemCol = (key, record) => {
        if (key == 'expectTotal' || key == 'name') {
            return record.scheduleShowVOS && record.scheduleShowVOS.map((item, index) => {
                return item.scheduleItemShowVOS && item.scheduleItemShowVOS.map((childItem, childIndex) => {
                    return (
                        <div style={{ height: `${this.srcHeight}px` }}
                            className={'scheduleVosItem itemP'}
                        >
                            {childItem[key]}
                        </div >
                    )
                })
            })
        }
    }

    searchBtnClick = (searchInfo) => {
        console.log(searchInfo)
        let params = {
            pkOrg: searchInfo['pkSrc'].length ? searchInfo['pkSrc'][0] : null,
            pkProject: searchInfo['pkProject'].length ? searchInfo['pkProject'] : null,
            pkMeasureindex: searchInfo['pkMeasureindex'].length ? searchInfo['pkMeasureindex'] : null,
            pkSchedule: searchInfo['pkSchedule'].length ? searchInfo['pkSchedule'] : null,
            startDate: searchInfo['sectionDate'].startTime ? Date.parse(searchInfo['sectionDate'].startTime) : null,
            endDate: searchInfo['sectionDate'].endTime ? Date.parse(searchInfo['sectionDate'].endTime) : null
        }
        console.log(params)
        queryProject(params).then((res) => {
            let data = res.data;
            console.log('yan', data)
            if (data.resultCode === 'ok') {
                if (data.result) {
                    vendorsSuccess({ 'text': `查询成功,共${data.result.length}条` })
                } else {
                    vendorsSuccess({ 'text': `查询成功` })
                }
                
             
                this.setState({
                    data: data.result == null? [] : data.result
                })
            } else {
                vendorsDanger({ 'text': data.exMsg })
            }
        })
    }

    setRowKey = (record, index) => {
        return index
    };
}

export default createYGCPage({})(ProjectIndicators);
